<script type="text/javascript" src="java/formval.js"></script>
<script type="text/javascript">
function validateOnSubmit(formElem) {
	var errs=0;
	if (!validatePresent(formElem.Titel,  	  'TitelError', true))  	errs = 1;
	if (!validatePresent(formElem.MenuTitel,  'MenuTitelError', true))  errs = 1;
	if (!validatePresent(formElem.StyleName,  'StyleNameError', true))  errs = 1;
	if (errs==0){
		formElem.submit();
	}
};
function editPage(formElem){
	formElem.addedit.value = 0;
	validateOnSubmit(formElem);
}
function addPage(formElem){
	formElem.addedit.value = 1;
	validateOnSubmit(formElem);
	
}
</script>
<?php
$TagID = 1;
if (!empty ($_GET["tag"]))
	$TagID = $_GET["tag"];
if ($_POST) {
	if (!empty ($_POST["StyleName"]) && !empty ($_POST["Titel"]) && !empty ($_POST["MenuTitel"])) {
		if ($_POST["addedit"] == 0) {
			$sql = "Update tags set " .
					"Style='{$_POST["StyleName"]}'" .
					",Titel='{$_POST["Titel"]}'" .
					",MenuTitel='{$_POST["MenuTitel"]}'" .
					",ParentID='{$_POST["ParentID"]}'" .
					" where ID=$TagID";
			mysql_query($sql, $_db_link);
		} else {
			$sql = "insert into
			tags (Style,Titel,MenuTitel,ParentID,ShowMenu)
			values('" . $_POST["Style"] . "'
			,'" . $_POST["Titel"] . "'
			,'" . $_POST["MenuTitel"] . "'" .
			",'" . $_POST["ParentID"] . "'" .
			",1" .
			")";
			$_rd = mysql_query($sql, $_db_link);
			$TagID = mysql_insert_id();
			$sql = "insert into tagrol (TagID,RolID,View,Edit)" .
					" values($TagID,1,1,0)";
			mysql_query($sql, $_db_link);
		}

		GotoURL("index.php?tag=$TagID");
	}
}
$sql = "select * from tags where ID=$TagID";
$_rd = mysql_query($sql, $_db_link);
if ($_rd) {
	$daten = mysql_fetch_array($_rd, MYSQL_ASSOC);
}
$selected = "<option value='{$daten['Style']}' selected >{$daten['Style']}</option>";
$PagesList = "<select name='ParentID' id='ParentID'>";
getListBox($PagesList, $daten["ParentID"], "tags", "");
$PagesList .= "</select>";
?>
<form method="POST" id="addEditor" action="">

	<div
		style="width: 25%; background-color: #F1EEF3; margin: 0px; float: left;">
		<table class="tableEdit">
			<tr>
				<td class="lableEdit"><?PHP  LangText("Titel");?>:*</td>
				<td class="inputEdit"><input type="text" name="Titel" id="Titel"
					onchange="validatePresent(this, 'TitelError');"
					value='<?PHP echo $daten["Titel"]; ?>' /></td>
				<td class="validateEdit"><input type="label" id="TitelError"
					value='<?PHP LangText("TitelError");?>' /></td>
			</tr>
			<tr>
				<td class="lableEdit"><?PHP  LangText("MenuTitel");?>:*</td>
				<td class="inputEdit"><input type="text" name="MenuTitel"
					id="MenuTitel" onchange="validatePresent(this, 'MenuTitelError');"
					value='<?PHP echo $daten["MenuTitel"]; ?>' /></td>
				<td class="validateEdit"><input type="label" id="MenuTitelError"
					value='<?PHP LangText("MenuTitelError");?>' /></td>
			</tr>
		</table>
	</div>
	<div
		style="width: 25%; background-color: #F1EEF3; margin: 0px; float: left;">
		<table class="tableEdit">
			<tr>
				<td class="lableEdit"><?PHP  LangText("ParentPage");?>:*</td>
				<td class="inputEdit"><?php echo $PagesList;?></td>
				<td class="validateEdit"><input type="label" id="ParentIDError"
					value='<?PHP LangText("ParentIDError");?>' /></td>
			</tr>
			<tr>
				<td class="lableEdit"><?PHP  LangText("StyleName");?>:*</td>
				<td class="inputEdit"><select name="StyleName">
						<?php echo $selected; ?>
						<option value=" ">Normal</option>
						<option value="Rot-Sub">Rot-Sub</option>
						<option value="shopping">Shopping</option>
						<option value="Hotel">Hotel</option>
						<option value="Touren">Touren</option>
						<option value="Oouren">Origin</option>
				</select>
				</td>
				<td class="validateEdit"><input type="label" id="StyleNameError"
					value='<?PHP LangText("StyleNameError");?>' /></td>
				<td class="validateEdit"><input type="text" id="addedit"
					name="addedit" value='' /></td>
			</tr>
		</table>
	</div>


	<table>
		<tr>
			<td>&nbsp;</td>
			<td></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td></td>
		</tr>
	</table>
	<input type="button" name"save" id='save'
		onclick="editPage(this.form);" class="BootenLink"
		value='<?PHP LangText("Bearbeiten");?>' /> <input type="button"
		name"addnow" id='addnow' onclick="addPage(this.form);"
		class="BootenLink" value='<?PHP LangText("addnow");?>' />
</form>
